<template>
  <div class="form">
    <label for="">姓名：<input type="text" name="" id="" v-model="name"></label><br>
    <label for="">年龄：<input type="text" name="" id="" v-model="age"></label><br>
    <label for="">身高：<input type="text" name="" id="" v-model="height">(米)</label><br>
    <label for="">体重：<input type="text" name="" id="" v-model="weight">(公斤)</label><br>
    <label for="">病史：<input type="text" name="" id="" v-model="disease" ></label><br>
    <button @click="diagnose">诊断</button>
    <div class="res" v-show="res">{{ `患者 ${name} 的诊断结果：${res}` }}</div>
  </div>
</template>
<style>
</style>
<script>
export default {
  data() {
    return {
      name:'',
      age:'',
      height:0,
      weight:0,
      disease:'',
      BMI:0,
      res:''
    }
  },
  methods:{
    diagnose() {
      
      if(!this.name.trim() || !this.age.trim() || !this.weight.trim() || !this.height.trim())  return alert('信息未填写')
      this.BMI = this.weight / (this.height*this.height) 
      if (this.BMI <= 18.5) {
        this.res = '体重过轻'
      } else if(this.BMI <= 24.9) {
        this.res = '正常'
      } else if(this.BMI <= 29.9) {
        this.res = '体重过重'
      } else {
        this.res = '肥胖'
      }
      console.log(this.BMI);
      
    }
  }

}
</script>